package top.breezes.common;

import org.h2.api.ErrorCode;

/**
 * @author yuchengxin
 * @Date 2020-05-28 11:01
 * @Description
 */
public class Response<T> {

    private static final String SUCCESS_CODE = "1";
    private static final String ERROR_CODE = "-1";
    private static final String SUCCESS_MESSAGE = "操作成功";
    private static final String ERROR_MESSAGE = "操作失败";

    private String code;
    private String message;
    private T data;

    public Response(String code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> Response<T> success(T data) {
        return new Response<T>(SUCCESS_CODE, SUCCESS_MESSAGE, data);
    }

    public static <T> Response<T> success(String code, String message, T data) {
        return new Response<T>(code, message, data);
    }

    public static <T> Response<T> error(T data) {
        return new Response<T>(ERROR_CODE, ERROR_MESSAGE, data);
    }

    public static <T> Response<T> error(String code, String message, T data) {
        return new Response<T>(code, message, data);
    }
}
